home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / dde2 / ddexl.frm < prev    next >
Text File  |  1993-05-16  |  4KB  |  165 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "DDE Client to Excel"
  4.    ClientHeight    =   4290
  5.    ClientLeft      =   1320
  6.    ClientTop       =   1785
  7.    ClientWidth     =   7245
  8.    Height          =   4695
  9.    Left            =   1260
  10.    LinkMode        =   1  'Source
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   4290
  13.    ScaleWidth      =   7245
  14.    Top             =   1440
  15.    Width           =   7365
  16.    Begin TextBox Text1 
  17.       Height          =   1095
  18.       Left            =   600
  19.       MultiLine       =   -1  'True
  20.       TabIndex        =   0
  21.       Text            =   "Data"
  22.       Top             =   1200
  23.       Width           =   2175
  24.    End
  25.    Begin CommandButton Command2 
  26.       Caption         =   "Manual Link / Update"
  27.       Height          =   375
  28.       Left            =   3600
  29.       TabIndex        =   2
  30.       Top             =   1200
  31.       Width           =   2235
  32.    End
  33.    Begin CommandButton Command1 
  34.       Caption         =   "Auto Link"
  35.       Height          =   375
  36.       Left            =   3600
  37.       TabIndex        =   1
  38.       Top             =   1800
  39.       Width           =   2265
  40.    End
  41.    Begin CommandButton Command4 
  42.       Caption         =   "Poke"
  43.       Height          =   375
  44.       Left            =   3600
  45.       TabIndex        =   3
  46.       Top             =   2400
  47.       Width           =   2280
  48.    End
  49.    Begin TextBox Text2 
  50.       Height          =   720
  51.       Left            =   570
  52.       MultiLine       =   -1  'True
  53.       ScrollBars      =   1  'Horizontal
  54.       TabIndex        =   4
  55.       Text            =   "Open Documents"
  56.       Top             =   2760
  57.       Width           =   2265
  58.    End
  59.    Begin CommandButton Command3 
  60.       Caption         =   "Get Document Names"
  61.       Height          =   450
  62.       Left            =   3600
  63.       TabIndex        =   5
  64.       Top             =   3000
  65.       Width           =   2415
  66.    End
  67.    Begin Label Label1 
  68.       Alignment       =   2  'Center
  69.       AutoSize        =   -1  'True
  70.       BorderStyle     =   1  'Fixed Single
  71.       Caption         =   "This form links to a document SERVER.XLS.  Excel is executed and the document is opened if necessary."
  72.       Height          =   615
  73.       Left            =   1440
  74.       TabIndex        =   6
  75.       Top             =   240
  76.       Width           =   3945
  77.       WordWrap        =   -1  'True
  78.    End
  79. End
  80. Option Explicit
  81.  
  82. Const NONE = 0         ' 0 - None
  83. Const LINK_SOURCE = 1    ' 1 - Source (forms only)
  84. Const LINK_AUTOMATIC = 1 ' 1 - Automatic (controls only)
  85. Const LINK_MANUAL = 2    ' 2 - Manual (controls only)
  86. Const LINK_NOTIFY = 3    ' 3 - Notify (controls only)
  87.  
  88. Sub Command1_Click ()
  89.     Text1.LinkMode = NONE
  90.     Text1.LinkMode = LINK_AUTOMATIC
  91. End Sub
  92.  
  93. Sub Command2_Click ()
  94.     Text1.LinkMode = NONE
  95.     Text1.LinkMode = LINK_MANUAL
  96.     Text1.LinkRequest
  97. End Sub
  98.  
  99. Sub Command3_Click ()
  100.     text2.LinkMode = NONE
  101.     text2.LinkTopic = "Excel|system"
  102.     text2.LinkItem = "topics"
  103.     text2.LinkMode = LINK_MANUAL
  104.     text2.LinkRequest
  105. End Sub
  106.  
  107. Sub Command4_Click ()
  108.     Text1.LinkMode = NONE
  109.     Text1.LinkMode = LINK_MANUAL
  110.     Text1.LinkPoke
  111. End Sub
  112.  
  113. Sub Form_Load ()
  114.     Dim rc As Integer
  115.     Dim IsOpen As Integer
  116.     Dim TheCmd As String
  117.  
  118.     'Test to see if App is running...
  119.     On Error GoTo startup
  120.  
  121. reentry:
  122.     Text1.LinkMode = NONE
  123.     Text1.LinkTopic = "Excel|System"
  124.     Text1.LinkItem = "Topics"
  125.     Text1.LinkMode = LINK_MANUAL
  126.     Text1.LinkRequest
  127.     Text1.LinkTimeout = 300
  128.     
  129.     'The linkitem TOPICS returns a list of all open spreadsheets
  130.     'Test if sheet is open.
  131.     IsOpen = InStr(UCase$(Text1.Text), UCase$("source.xls"))
  132.     text2.Text = Str$(IsOpen)
  133.  
  134.     If IsOpen = 0 Then
  135.     'Document is not open
  136.     On Error GoTo nosheet
  137.     TheCmd = "[OPEN(" + """"
  138.     TheCmd = TheCmd$ + "c:\vbdemos\dde\source.xls" + """" + ",1)]"
  139.     Text1.LinkExecute TheCmd
  140.     End If
  141.  
  142.     'Set link to correct row/cell location
  143.     Text1.LinkMode = NONE
  144.     Text1.LinkTopic = "Excel|SOURCE.XLS"
  145.     Text1.LinkItem = "R1C1"
  146.     Text1.LinkMode = LINK_AUTOMATIC
  147.     
  148.     Exit Sub
  149.  
  150. startup:
  151.     If Err = 282 Then
  152.     rc = Shell("c:\excel\Excel c:\vbdemos\dde\source.xls", 7)
  153.     Resume reentry
  154.     Else
  155.     MsgBox "Unknown DDE error."
  156.     Exit Sub
  157.     End If
  158.  
  159. nosheet:
  160.     MsgBox "Unable to open sheet."
  161.     Exit Sub
  162.  
  163. End Sub
  164.  
  165.